package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.preCheckCreateMchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymatou.iapi.godmch.service.preCheckCreateMchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*新增商户预校验
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_preCheckCreateMch{
	private static preCheckCreateMchBean bean;
	private static preCheckCreateMchCall call;
	 createmchBean cmBean=new createmchBean();
	createmchCall cmcall=new createmchCall();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增商户预校验");
	}

	@Before
	public void caseUp() {
		bean=new preCheckCreateMchBean();
		call=new preCheckCreateMchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_001() {
		Logger.start(true,"正例-新增商户预校验-邀请码与国家码一致");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			bean.setCountry(cmBean.getCountry());
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_001_1() {
		Logger.start(true,"正例-新增商户预校验-邀请码与国家码不一致(现在返回成功 跨国20191023修改)");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			bean.setCountry("DEU");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
//			Logger.verifyEquals("5018", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("结算币种与上级商户不一致"), "验证返回Message值");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_002() {
		Logger.start(true,"反例-新增商户预校验-国家码为空");
		try {
			
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
//			// 代理
//			createmchBean bean2 = new createmchBean();
//			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			//bean.setCountry("DEU");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("国家码不能为空"), "验证返回Message值");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_003() {
		Logger.start(true,"反例-新增商户预校验-特殊商户,特殊商户是500182875(不同国家，比喻香港可以代理日本)");
		try {

			int userId1 =500182875;//国家是香港 HKG
			
			bean.setCountry("JPN");
			bean.setCode("B6G9DU");
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_003_2() {
		Logger.start(true,"反例-新增商户预校验-特殊商户,特殊商户是500182875(可以代理 任何国家，跨国20191023修改)");
		try {

			int userId1 =500182875;//国家是香港 HKG
			
			bean.setCountry("KOR");//韩国
			bean.setCode("B6G9DU");
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_004() {
		Logger.start(true,"反例-新增商户预校验-特殊商户,特殊商户是500182875(比喻香港可以代理香港)");
		try {

			int userId1 =500182875;//国家是香港 HKG
			
			bean.setCountry("HKG");
			bean.setCode("B6G9DU");
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_005() {
		Logger.start(true,"正例-新增商户预校验-邀请码与国家码一致,校验普通用不可以 香港代理日本(现在返回成功 跨国20191023修改)");
		try {
			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			cmBean.setCountry("HKG");
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);

			bean.setCountry("JPN");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
//			Logger.verifyEquals("5018", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("结算币种与上级商户不一致"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_006() {
		Logger.start(true,"反例-新增商户预校验-支持指定代理国家-20191112修改跨国代理");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			cmBean.setCountry("BEL");
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			bean.setCountry("USA");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_007() {
		Logger.start(true,"反例-新增商户预校验-支持指定代理国家 之外-20191112修改跨国代理");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			cmBean.setCountry("JPN");
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			bean.setCountry("CAN");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("渠道商不支持该国代理：CAN", call.getMessage(), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_preCheckCreateMch_008() {
		Logger.start(true,"反例-新增商户预校验-邀请码与国家码不一致,但是邀请码的国家支持所有国家-20191112修改跨国代理");
		try {

			int userId1 = GodmchManageCallService.UserCreateAgent();
			// 创建渠道
			cmBean = GodmchManageCallService.InitcreatemchBeanForChannel(userId1);
			cmBean.setCountry("USA");
			GodmchManageCallService.createmchCallForChannel(cmBean);
			// 渠道商邀请码
			CreateCodeBean createCodeBean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId1);
			CreateCodeCall createcall = GodmchManageCallService.createCodeCall(createCodeBean);
			// 代理
			createmchBean bean2 = new createmchBean();
			int userId2 = GodmchManageCallService.UserCreateAgent();
			
			bean.setCountry("CHE");
			bean.setCode(createcall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功success值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}